From ef5ed26a903c38ea9601e693dcea8caad79a29f2 Mon Sep 17 00:00:00 2001 From: parkrrrr Date: Tue, 8 Jun 2004 17:42:12 +0000 Subject: [PATCH] Added 'logs' option to text/html/palmdoc --- gpsbabel/defs.h | 7 ++++ gpsbabel/gpx.c | 1 - gpsbabel/html.c | 95 +++++++++++++++++++++++++++++++++++++++++++++- gpsbabel/palmdoc.c | 87 ++++++++++++++++++++++++++++++++++++++++++ gpsbabel/text.c | 87 ++++++++++++++++++++++++++++++++++++++++++ gpsbabel/util.c | 54 ++++++++++++++++++++++++++ 6 files changed, 328 insertions(+), 3 deletions(-) diff --git a/gpsbabel/defs.h b/gpsbabel/defs.h index 3fbe48bb3..85b275c10 100644 --- a/gpsbabel/defs.h +++ b/gpsbabel/defs.h @@ -435,6 +435,13 @@ char * strip_nastyhtml(const char * in); char * str_utf8_to_cp1252( const char * str ); char * str_utf8_to_ascii( const char * str ); +/* this lives in gpx.c */ +time_t xml_parse_time( char *cdatastr ); + +xml_tag *xml_findfirst( xml_tag *root, char *tagname ); +xml_tag *xml_findnext( xml_tag *root, xml_tag *cur, char *tagname ); +char *xml_attribute( xml_tag *tag, char *attrname ); + char * rot13( const char *str ); /* diff --git a/gpsbabel/gpx.c b/gpsbabel/gpx.c index 871aa8fc5..ba12e4b14 100644 --- a/gpsbabel/gpx.c +++ b/gpsbabel/gpx.c @@ -542,7 +542,6 @@ gs_get_container(geocache_container t) return "Unknown"; } -static time_t xml_parse_time( char *cdatastr ) { diff --git a/gpsbabel/html.c b/gpsbabel/html.c index 41a71d886..4a55924e3 100644 --- a/gpsbabel/html.c +++ b/gpsbabel/html.c @@ -29,6 +29,7 @@ static void *mkshort_handle; static char *stylesheet = NULL; static char *encrypt = NULL; +static char *includelogs = NULL; #define MYNAME "HTML" @@ -38,6 +39,8 @@ arglist_t html_args[] = { "Path to HTML style sheet", ARGTYPE_STRING }, { "encrypt", &encrypt, "Encrypt hints using ROT13", ARGTYPE_BOOL }, + { "logs", &includelogs, + "Include groundspeak logs if present", ARGTYPE_BOOL }, {0, 0, 0, 0} }; @@ -81,8 +84,8 @@ html_disp(const waypoint *wpt) fprintf(file_out, "
\n", wpt->shortname); fprintf(file_out, "

%s - %c%d°%06.3f %c%d°%06.3f (%ld%c %6.0f %7.0f)", (global_opts.synthesize_shortnames) ? mkshort(mkshort_handle, wpt->description) : wpt->shortname, - wpt->latitude < 0 ? 'S' : 'N', abs(latint), 60.0 * (fabs(wpt->latitude) - latint), - wpt->longitude < 0 ? 'W' : 'E', abs(lonint), 60.0 * (fabs(wpt->longitude) - lonint), + wpt->latitude < 0 ? 'S' : 'N', latint, 60.0 * (fabs(wpt->latitude) - latint), + wpt->longitude < 0 ? 'W' : 'E', lonint, 60.0 * (fabs(wpt->longitude) - lonint), utmz, utmzc, utme, utmn); if (wpt->altitude != unknown_alt) fprintf (file_out, " alt: %1.1f", wpt->altitude); @@ -119,6 +122,94 @@ html_disp(const waypoint *wpt) else if (!wpt->notes && (!wpt->description || strcmp(wpt->notes,wpt->description))) { fprintf (file_out, "

%s

\n", wpt->notes); } + if ( includelogs && wpt->gpx_extras ) { + xml_tag *root = wpt->gpx_extras; + xml_tag *curlog = NULL; + xml_tag *logpart = NULL; + curlog = xml_findfirst( root, "groundspeak:log" ); + while ( curlog ) { + fprintf( file_out, "

\n" ); + time_t logtime = 0; + struct tm *logtm = NULL; + + logpart = xml_findfirst( curlog, "groundspeak:type" ); + if ( logpart ) { + fprintf( file_out, "%s by ", logpart->cdata ); + } + + logpart = xml_findfirst( curlog, "groundspeak:finder" ); + if ( logpart ) { + char *f = html_entitize( logpart->cdata ); + fprintf( file_out, "%s on ", f ); + xfree( f ); + } + + logpart = xml_findfirst( curlog, "groundspeak:date" ); + if ( logpart ) { + logtime = xml_parse_time( logpart->cdata ); + logtm = localtime( &logtime ); + if ( logtm ) { + fprintf( file_out, + "%2.2d/%2.2d/%4.4d
\n", + logtm->tm_mon+1, + logtm->tm_mday, + logtm->tm_year+1900 + ); + } + } + + logpart = xml_findfirst( curlog, "groundspeak:log_wpt" ); + if ( logpart ) { + char *coordstr = NULL; + float lat = 0; + int latdeg = 0; + float lon = 0; + int londeg = 0; + coordstr = xml_attribute( logpart, "lat" ); + if ( coordstr ) { + lat = atof( coordstr ); + } + coordstr = xml_attribute( logpart, "lon" ); + if ( coordstr ) { + lon = atof( coordstr ); + } + latdeg = abs(lat); + londeg = abs(lon); + + fprintf( file_out, + "%c %d° %.3f' %c %d° %.3f'
\n", + + lat < 0 ? 'S' : 'N', latdeg, 60.0 * (fabs(lat) - latdeg), + lon < 0 ? 'W' : 'E', londeg, 60.0 * (fabs(lon) - londeg) + ); + } + + logpart = xml_findfirst( curlog, "groundspeak:text" ); + if ( logpart ) { + char *encstr = NULL; + char *s = NULL; + char *t = NULL; + int encoded = 0; + encstr = xml_attribute( logpart, "encoded" ); + encoded = (encstr[0] != 'F'); + + if ( encrypt && encoded ) { + s = rot13( logpart->cdata ); + } + else { + s = xstrdup( logpart->cdata ); + } + + t = html_entitize( s ); + fprintf( file_out, "%s", t ); + xfree( t ); + xfree( s ); + } + + fprintf( file_out, "

\n" ); + curlog = xml_findnext( root, curlog, "groundspeak:log" ); + } + } fprintf(file_out, "

\n"); } diff --git a/gpsbabel/palmdoc.c b/gpsbabel/palmdoc.c index da0416c11..802a0f255 100644 --- a/gpsbabel/palmdoc.c +++ b/gpsbabel/palmdoc.c @@ -37,6 +37,7 @@ static struct pdb_record *opdb_rec; static char *suppresssep = NULL; static char *dbname = NULL; +static char *includelogs = NULL; static int ct = 1; static int offset = 0; @@ -68,6 +69,8 @@ arglist_t palmdoc_args[] = { "Suppress separator lines between waypoints", ARGTYPE_BOOL }, {"dbname", &dbname, "Database name", ARGTYPE_STRING }, {"encrypt", &encrypt, "Encrypt hints with ROT13", ARGTYPE_BOOL }, + { "logs", &includelogs, + "Include groundspeak logs if present", ARGTYPE_BOOL }, {0, 0, 0, 0} }; @@ -457,6 +460,90 @@ palmdoc_disp(const waypoint *wpt) else if (wpt->notes && (!wpt->description || strcmp(wpt->notes,wpt->description))) { docprintf (10+strlen(wpt->notes), "%s\n", wpt->notes); } + + if ( includelogs && wpt->gpx_extras ) { + xml_tag *root = wpt->gpx_extras; + xml_tag *curlog = NULL; + xml_tag *logpart = NULL; + curlog = xml_findfirst( root, "groundspeak:log" ); + while ( curlog ) { + docprintf( 10, "\n" ); + time_t logtime = 0; + struct tm *logtm = NULL; + + logpart = xml_findfirst( curlog, "groundspeak:type" ); + if ( logpart ) { + docprintf( 10+strlen(logpart->cdata), "%s by ", logpart->cdata ); + } + + logpart = xml_findfirst( curlog, "groundspeak:finder" ); + if ( logpart ) { + docprintf( 10+strlen(logpart->cdata), "%s on ", logpart->cdata ); + } + + logpart = xml_findfirst( curlog, "groundspeak:date" ); + if ( logpart ) { + logtime = xml_parse_time( logpart->cdata ); + logtm = localtime( &logtime ); + if ( logtm ) { + docprintf( 15, + "%2.2d/%2.2d/%4.4d\n", + logtm->tm_mon+1, + logtm->tm_mday, + logtm->tm_year+1900 + ); + } + } + + logpart = xml_findfirst( curlog, "groundspeak:log_wpt" ); + if ( logpart ) { + char *coordstr = NULL; + float lat = 0; + int latdeg = 0; + float lon = 0; + int londeg = 0; + coordstr = xml_attribute( logpart, "lat" ); + if ( coordstr ) { + lat = atof( coordstr ); + } + coordstr = xml_attribute( logpart, "lon" ); + if ( coordstr ) { + lon = atof( coordstr ); + } + latdeg = abs(lat); + londeg = abs(lon); + + docprintf( 30, + "%c %d\xb0 %.3f' %c %d\xb0 %.3f'\n", + + lat < 0 ? 'S' : 'N', latdeg, 60.0 * (fabs(lat) - latdeg), + lon < 0 ? 'W' : 'E', londeg, 60.0 * (fabs(lon) - londeg) + ); + } + + logpart = xml_findfirst( curlog, "groundspeak:text" ); + if ( logpart ) { + char *encstr = NULL; + char *s = NULL; + int encoded = 0; + encstr = xml_attribute( logpart, "encoded" ); + encoded = (encstr[0] != 'F'); + + if ( encrypt && encoded ) { + s = rot13( logpart->cdata ); + } + else { + s = xstrdup( logpart->cdata ); + } + + docprintf( 5+strlen(s), "%s", s ); + xfree( s ); + } + + docprintf( 10, "\n" ); + curlog = xml_findnext( root, curlog, "groundspeak:log" ); + } + } if (! suppresssep) docprintf(50, "---------------------------\n"); else diff --git a/gpsbabel/text.c b/gpsbabel/text.c index 6c17eb902..f133da47c 100644 --- a/gpsbabel/text.c +++ b/gpsbabel/text.c @@ -29,6 +29,7 @@ static void *mkshort_handle; static char *suppresssep = NULL; static char *encrypt = NULL; +static char *includelogs = NULL; #define MYNAME "TEXT" @@ -38,6 +39,8 @@ arglist_t text_args[] = { "Suppress separator lines between waypoints", ARGTYPE_BOOL }, { "encrypt", &encrypt, "Encrypt hints using ROT13", ARGTYPE_BOOL }, + { "logs", &includelogs, + "Include groundspeak logs if present", ARGTYPE_BOOL }, {0, 0, 0, 0} }; @@ -112,6 +115,90 @@ text_disp(const waypoint *wpt) else if (wpt->notes && (!wpt->description || strcmp(wpt->notes,wpt->description))) { fprintf (file_out, "%s\n", wpt->notes); } + + if ( includelogs && wpt->gpx_extras ) { + xml_tag *root = wpt->gpx_extras; + xml_tag *curlog = NULL; + xml_tag *logpart = NULL; + curlog = xml_findfirst( root, "groundspeak:log" ); + while ( curlog ) { + fprintf( file_out, "\n" ); + time_t logtime = 0; + struct tm *logtm = NULL; + + logpart = xml_findfirst( curlog, "groundspeak:type" ); + if ( logpart ) { + fprintf( file_out, "%s by ", logpart->cdata ); + } + + logpart = xml_findfirst( curlog, "groundspeak:finder" ); + if ( logpart ) { + fprintf( file_out, "%s on ", logpart->cdata ); + } + + logpart = xml_findfirst( curlog, "groundspeak:date" ); + if ( logpart ) { + logtime = xml_parse_time( logpart->cdata ); + logtm = localtime( &logtime ); + if ( logtm ) { + fprintf( file_out, + "%2.2d/%2.2d/%4.4d\n", + logtm->tm_mon+1, + logtm->tm_mday, + logtm->tm_year+1900 + ); + } + } + + logpart = xml_findfirst( curlog, "groundspeak:log_wpt" ); + if ( logpart ) { + char *coordstr = NULL; + float lat = 0; + int latdeg = 0; + float lon = 0; + int londeg = 0; + coordstr = xml_attribute( logpart, "lat" ); + if ( coordstr ) { + lat = atof( coordstr ); + } + coordstr = xml_attribute( logpart, "lon" ); + if ( coordstr ) { + lon = atof( coordstr ); + } + latdeg = abs(lat); + londeg = abs(lon); + + fprintf( file_out, + "%c %d %.3f' %c %d %.3f'\n", + + lat < 0 ? 'S' : 'N', latdeg, 60.0 * (fabs(lat) - latdeg), + lon < 0 ? 'W' : 'E', londeg, 60.0 * (fabs(lon) - londeg) + ); + } + + logpart = xml_findfirst( curlog, "groundspeak:text" ); + if ( logpart ) { + char *encstr = NULL; + char *s = NULL; + int encoded = 0; + encstr = xml_attribute( logpart, "encoded" ); + encoded = (encstr[0] != 'F'); + + if ( encrypt && encoded ) { + s = rot13( logpart->cdata ); + } + else { + s = xstrdup( logpart->cdata ); + } + + fprintf( file_out, "%s", s ); + xfree( s ); + } + + fprintf( file_out, "\n" ); + curlog = xml_findnext( root, curlog, "groundspeak:log" ); + } + } if (! suppresssep) fprintf(file_out, "-----------------------------------------------------------------------------\n"); else diff --git a/gpsbabel/util.c b/gpsbabel/util.c index 25ffad8ca..3804a908f 100644 --- a/gpsbabel/util.c +++ b/gpsbabel/util.c @@ -1075,3 +1075,57 @@ char * html_entitize(const char * str) { return entitize(str, 1); } + +/* + * xml_tag utilities + */ + +xml_tag *xml_next( xml_tag *root, xml_tag *cur ) +{ + if ( cur->child ) { + cur = cur->child; + } + else if ( cur->sibling ) { + cur = cur->sibling; + } + else { + cur = cur->parent; + if ( cur == root ) { + cur = NULL; + } + if ( cur ) { + cur = cur->sibling; + } + } + return cur; +} + +xml_tag *xml_findnext( xml_tag *root, xml_tag *cur, char *tagname ) +{ + xml_tag *result = cur; + do { + result = xml_next( root, result ); + } while ( result && case_ignore_strcmp( result->tagname, tagname )); + return result; +} + +xml_tag *xml_findfirst( xml_tag *root, char *tagname ) +{ + return xml_findnext( root, root, tagname ); +} + +char *xml_attribute( xml_tag *tag, char *attrname ) +{ + char *result = NULL; + if ( tag->attributes ) { + char **attr = tag->attributes; + while ( attr && *attr ) { + if ( 0 == case_ignore_strcmp( *attr, attrname )) { + result = attr[1]; + break; + } + attr+=2; + } + } + return result; +} -- 2.30.2